from PySide6.QtWidgets import QTextEdit, QWidget, QVBoxLayout
from PySide6.QtCore import QSize
from components.base_component import DraggableComponent

class TextDisplayComponent(DraggableComponent):
    """文本显示组件"""
    def __init__(self, component_id, text, parent=None):
        super().__init__(component_id, parent)
        self.title_label.setText(f"文本显示: {component_id}")
        
        # 设置文本显示组件的最小尺寸
        self.setMinimumSize(260, 220)
        
        # 确保内容区域足够大
        self.content.setMinimumHeight(150)
        
        # 容器布局
        container = QWidget()
        container.setStyleSheet("background-color: transparent; border: none;")
        container_layout = QVBoxLayout(container)
        container_layout.setContentsMargins(0, 0, 0, 0)
        
        # 添加文本显示框 - 增大文本框尺寸
        self.text_display = QTextEdit()
        self.text_display.setReadOnly(True)
        self.text_display.setText(text)
        self.text_display.setMinimumSize(230, 140)
        self.text_display.setStyleSheet("""
            QTextEdit {
                font-size: 14px;
                line-height: 150%;
                border: 1px solid #cccccc;
                border-radius: 4px;
                background-color: white;
                padding: 10px;
                margin: 5px;
            }
        """)
        container_layout.addWidget(self.text_display)
        
        # 添加容器到内容布局
        self.content_layout.addWidget(container)
    
    def set_text(self, text):
        """设置显示文本"""
        self.text_display.setText(text)
    
    def sizeHint(self):
        """提供文本显示组件的默认尺寸建议"""
        return QSize(300, 250) 